﻿(function () {
    'use strict';
    angular.module('SpaDemo').factory("announcementsDataContext", ['$q', 'announcementMapper', 'announcementCrudSrv',
        function dataContext($q, announcementMapper, announcementCrudSrv) {
            function _getData() {
                return $q.when(announcementCrudSrv.getDataFromList()
                    .then(function (data) {
                        var dataDto = announcementMapper.toAnnouncements(data);
                        console.table(dataDto);
                        return dataDto;
                    })
                    .fail(function (error) {
                        //add error handler 
                        console.log('Failed to get data from employeeSvc.newEmployee()');
                    }));
            }

            var service = {
                getData: _getData
            };

            return service;
        }
    ]);
})();